package gongshw.homework;


import java.util.Vector;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

/**
 * Application Lifecycle Listener implementation class LoginListener
 *
 */
public class LoginListener implements HttpSessionBindingListener {
	
	private static Vector<String> v = new Vector<String>();
	private String id;

    /**
     * Default constructor. 
     */
	public LoginListener() {
        // TODO Auto-generated constructor stub
    }
	
	
    public LoginListener(String id) {
        // TODO Auto-generated constructor stub
    	this.id = id;
    }

	/**
     * @see HttpSessionBindingListener#valueUnbound(HttpSessionBindingEvent)
     */
    public synchronized void valueUnbound(HttpSessionBindingEvent arg0) {
        // TODO Auto-generated method stub
    	System.out.println("valueUnbound");
    	v.remove(id);
    }

	/**
     * @see HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)
     */
    public synchronized void valueBound(HttpSessionBindingEvent arg0) {
        // TODO Auto-generated method{
    	System.out.println("valueBound");
		if(v.indexOf(id)<0){
    		v.add(id);
    	}
    }
    
    public static int getCount(){
    	return v.size();
    }
	
}
